package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysNotifyConfigDAO;
import com.ourteam.system.dao.SysNotifyConfig;
import com.ourteam.system.dao.SysNotifyConfigDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:38
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysNotifyConfigDAOJdbcImpl extends AbstractSpringDAO
    implements ISysNotifyConfigDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            CheckInterval, Id, NotifyIcon, NotifyListener, NotifyMessage,
            NotifyName, Status, ViewPath
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.CheckInterval, _DataObjectProperty.Id,
            _DataObjectProperty.NotifyIcon, _DataObjectProperty.NotifyListener,
            _DataObjectProperty.NotifyMessage, _DataObjectProperty.NotifyName,
            _DataObjectProperty.Status, _DataObjectProperty.ViewPath
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysNotifyConfig, SysNotifyConfigDAOQueryBean> daoHelper;

    public AbstractSysNotifyConfigDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysNotifyConfig, SysNotifyConfigDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysNotifyConfig
         * @throws Exception
         */
    public boolean checkIsUnique(SysNotifyConfig aSysNotifyConfig)
        throws Exception {
        if (aSysNotifyConfig == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysNotifyConfig.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysNotifyConfig
     * @throws Exception
     */
    public void insert(SysNotifyConfig aSysNotifyConfig)
        throws Exception {
        super.doInsert(aSysNotifyConfig);
    }

    /**
         * Batch Insert Datas
         * @param aSysNotifyConfig
         * @throws Exception
         */
    public void batchInsert(SysNotifyConfig[] aSysNotifyConfigs)
        throws Exception {
        super.doBatchInsert(aSysNotifyConfigs);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysNotifyConfigDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysNotifyConfig aSysNotifyConfig)
        throws Exception {
        delete(aSysNotifyConfig.getId());
    }

    /**
     * Update Data Selective
     * @param aSysNotifyConfig
     * @throws Exception
     */
    public void update(SysNotifyConfig aSysNotifyConfig)
        throws Exception {
        if (aSysNotifyConfig.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysNotifyConfig);

        SysNotifyConfig tempObj = findById(aSysNotifyConfig.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysNotifyConfig, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysNotifyConfigs[]
     * @throws Exception
     */
    public void batchUpdate(SysNotifyConfig[] aSysNotifyConfigs)
        throws Exception {
        super.doBatchUpdate(aSysNotifyConfigs);
    }

    /**
         * Update Data By Condictions
         * @param aSysNotifyConfig
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysNotifyConfig aSysNotifyConfig,
        SysNotifyConfigDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aSysNotifyConfig, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysNotifyConfigDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysNotifyConfig aSysNotifyConfig)
        throws Exception {
        if (aSysNotifyConfig.getViewPath() == null) {
            throw new Exception(
                "The SysNotifyConfig.viewPath value is not allow NULL");
        }

        if (aSysNotifyConfig.getNotifyIcon() == null) {
            throw new Exception(
                "The SysNotifyConfig.notifyIcon value is not allow NULL");
        }

        if (aSysNotifyConfig.getNotifyListener() == null) {
            throw new Exception(
                "The SysNotifyConfig.notifyListener value is not allow NULL");
        }

        if (aSysNotifyConfig.getNotifyMessage() == null) {
            throw new Exception(
                "The SysNotifyConfig.notifyMessage value is not allow NULL");
        }

        if (aSysNotifyConfig.getNotifyName() == null) {
            throw new Exception(
                "The SysNotifyConfig.notifyName value is not allow NULL");
        }

        if (aSysNotifyConfig.getStatus() == null) {
            throw new Exception(
                "The SysNotifyConfig.status value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysNotifyConfig findById(final long id) throws Exception {
        SysNotifyConfigDAOQueryBean queryBean = new SysNotifyConfigDAOQueryBean();

        SysNotifyConfigDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysNotifyConfig[] SysNotifyConfigs = query(queryBean);

        if (SysNotifyConfigs.length == 0) {
            return null;
        } else {
            return SysNotifyConfigs[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysNotifyConfig[]
         * @throws Exception
         */
    public SysNotifyConfig[] query(SysNotifyConfigDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcSysNotifyConfigRowMapper());

        return (SysNotifyConfig[]) result.toArray(new SysNotifyConfig[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysNotifyConfigDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysNotifyConfigDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysNotifyConfig[] aSysNotifyConfigs,
        SysNotifyConfigDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysNotifyConfigs, queryBean);
    }

    public void synchronize(SysNotifyConfig[] aSysNotifyConfigs,
        SysNotifyConfigDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysNotifyConfig> callBack)
        throws Exception {
        daoHelper.synchronize(aSysNotifyConfigs, queryBean, callBack);
    }

    public static class JdbcSysNotifyConfigRowMapper implements RowMapper<SysNotifyConfig> {
        public SysNotifyConfig mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysNotifyConfig object = new SysNotifyConfig();

            int columnIndex = 1;

            int __dataType;

            try {
                Object checkInterval = null;

                checkInterval = resultSet.getObject(columnIndex++);

                object.setCheckIntervalNull(resultSet.getBoolean(columnIndex++));

                if (checkInterval != null) {
                    setBeanValue(object, _DataObjectProperty.CheckInterval,
                        checkInterval);
                }

                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object notifyIcon = null;

                notifyIcon = resultSet.getObject(columnIndex++);

                object.setNotifyIconNull(resultSet.getBoolean(columnIndex++));

                if (notifyIcon != null) {
                    setBeanValue(object, _DataObjectProperty.NotifyIcon,
                        notifyIcon);
                }

                Object notifyListener = null;

                notifyListener = resultSet.getObject(columnIndex++);

                object.setNotifyListenerNull(resultSet.getBoolean(columnIndex++));

                if (notifyListener != null) {
                    setBeanValue(object, _DataObjectProperty.NotifyListener,
                        notifyListener);
                }

                Object notifyMessage = null;

                notifyMessage = resultSet.getObject(columnIndex++);

                object.setNotifyMessageNull(resultSet.getBoolean(columnIndex++));

                if (notifyMessage != null) {
                    setBeanValue(object, _DataObjectProperty.NotifyMessage,
                        notifyMessage);
                }

                Object notifyName = null;

                notifyName = resultSet.getObject(columnIndex++);

                object.setNotifyNameNull(resultSet.getBoolean(columnIndex++));

                if (notifyName != null) {
                    setBeanValue(object, _DataObjectProperty.NotifyName,
                        notifyName);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object viewPath = null;

                viewPath = resultSet.getObject(columnIndex++);

                object.setViewPathNull(resultSet.getBoolean(columnIndex++));

                if (viewPath != null) {
                    setBeanValue(object, _DataObjectProperty.ViewPath, viewPath);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
